package api

import (
	"context"

	"aigen-todo/internal/config"

	"github.com/gofiber/fiber/v2"
	"gorm.io/gorm"
)

type Server struct {
	App  *fiber.App
	Port string
}

func (s *Server) Start() error {
	return s.App.Listen(s.Port)
}

func (s *Server) Stop(ctx context.Context) error {
	return s.App.ShutdownWithContext(ctx)
}

// NewServer 创建新的服务器
func NewServer(cfg *config.Config, db *gorm.DB) *Server {
	// 创建Fiber应用
	app := SetupRouter(cfg, db)

	return &Server{
		App: app,
	}
}
